package br.com.uglyboys;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import br.com.uglyboys.control.CorreioController;
import br.com.uglyboys.service.BatTrackingService;

public class BatTrackingApp extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		exibirTelaMain();
		Intent svc = new Intent(this, BatTrackingService.class);
	    startService(svc);

	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		
		Intent svc = new Intent(this, BatTrackingService.class);
	    stopService(svc);
	}

	public void exibirTelaMain() {
		CorreioController.getInstancia(this);
		setContentView(R.layout.main);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

		final Button  btnAdd = (Button) findViewById(R.btn.btnAdd);
		btnAdd.setBackgroundDrawable(getResources().getDrawable(R.drawable.add));
		btnAdd.setOnFocusChangeListener(new View.OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if(hasFocus){
					btnAdd.setBackgroundDrawable(getResources().getDrawable(R.drawable.addfocus));
				}else{
					btnAdd.setBackgroundDrawable(getResources().getDrawable(R.drawable.add));
				}
			}
		});
		btnAdd.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(BatTrackingApp.this, TelaAdd.class);
				startActivity(intent);
			}
		});		
		
		
		
		final Button  btnSearch = (Button) findViewById(R.btn.btnSearch);
		btnSearch.setBackgroundDrawable(getResources().getDrawable(R.drawable.search));
		btnSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if(hasFocus){
					btnSearch.setBackgroundDrawable(getResources().getDrawable(R.drawable.searchfocus));
				}else{
					btnSearch.setBackgroundDrawable(getResources().getDrawable(R.drawable.search));
				}
			}
		});
		btnSearch.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(BatTrackingApp.this, TelaSearch.class);
				startActivity(intent);
			}
		});
	}
}